{extend name="platform/base" /} {block name="main"}
<div class="row padder-v">
    <div class="col-sm-9">
        <a href="{:__URL('PLATFORM_MAIN/Goods/addGoodsVariety')}" class="btn btn-sm btn-primary"><i
                class="fa fa-plus"></i> 添加 </a>
    </div>
</div>
<section class="panel panel-default">
    <table class="table table-striped b-light text-sm">
        <thead>
        <tr>
            <th>ID</th>
            <th class="center">图片</th>
            <th class="center">名称</th>
            <th class="center">描述</th>
            <th class="center">状态</th>
            <th class="center">排序</th>
            <th class="center">操作</th>
        </tr>
        </thead>
        <tbody id="list">
        <tr></tr>
        </tbody>
    </table>
    {include file="platform/page" /}
</section>

{/block} {block name="script"}
<script type="text/javascript">
    $(function () {
        LoadingInfo(1);
    });

    //查询用户列表
    function LoadingInfo(pageIndex) {
        var search_text = $("#search_text").val();
        $.ajax({
            type: "post",
            url: "{:__URL('PLATFORM_MAIN/Goods/GoodsVariety')}",

            async: true,
            data: {
                "pageIndex": pageIndex, "search_text": search_text
            },
            success: function (data) {
                console.log(data);
                var html = '';
                $("#total_count_num").text(data["total_count"]);
                $("#page_count_num").text(data["page_count"]);
                $("#page_count").val(data["page_count"]);
                $("#pageNumber a").remove();
                if (data["data"].length > 0) {
                    for (var i = 0; i < data["data"].length; i++) {
                        html += '<tr>';
                        html += '<td class="center">' + data["data"][i]["variety_id"] + '</td>';
                        html += '<td class="center"><img src="' + data["data"][i]["image"] + '" alt=""></td>';
                        html += '<td class="center">' + data["data"][i]["variety_name"] + '</td>';
                        html += '<td class="center">' + data["data"][i]["desc"] + '</td>';
                        html += data["data"][i]["type"] == 2 ? '<td  class="center" style="color:red;">锁定</td>' : '<td class="center" style="color:#0689e1;">正常</td>';
                        html += '<td class="center"><input type="number" value="' + data["data"][i]["sort"] + '" min="0"  onchange="sort(' + data["data"][i]["variety_id"] + ',this)"></td>';
                        html += '<td class="center">';
                        if (data["data"][i]["variety_id"] !== 0) {
                            html += '<a href="' + __URL('PLATFORM_MAIN/Goods/goodslist?batch=' + data["data"][i]["variety_id"]) + '">【 批量添加 】</a>';
                            html += '<a href="' + __URL('PLATFORM_MAIN/Goods/goodslist?variety_id=' + data["data"][i]["variety_id"]) + '">【 商品查看 】</a>';
                            html += '<a href="' + __URL('PLATFORM_MAIN/Goods/addGoodsVariety?variety_id=' + data["data"][i]["variety_id"]) + '">【 修改 】</a>';
                        } else {
                            if (data["data"][i]["type"] == 1) {
                                html += '<a href="javascript:;" onclick="sort(' + data["data"][i]["variety_id"] + ',2)">【 停用 】</a>';
                            } else {
                                html += '<a href="javascript:;"  onclick="sort(' + data["data"][i]["variety_id"] + ',1)">【 启用 】</a>';
                            }
                        }
                        html += '</tr>';
                    }
                } else {
                    html += '<tr><th colspan="6">暂无符合条件的数据记录</th></tr>';
                }
                $("#list").html(html);
                var totalpage = $("#page_count").val();
                if (totalpage == 1) {
                    changeClass("all");
                }
                var $html = pagenumShow(jumpNumber, totalpage, {$pageshow})
                $("#pageNumber").append($html);
            }
        });
    }

    function delGoodsVariety(variety_id) {
        $("#dialog").dialog({
            buttons: {
                "确定,#e57373": function () {
                    $(this).dialog('close');
                    $.ajax({
                        type: "post",
                        url: "{:__URL('PLATFORM_MAIN/Goods/delGoodsVariety')}",
                        async: true,
                        data: {
                            "variety_id": variety_id
                        },
                        success: function (data) {
                            if (data > 0) {
                                showMessage('success', "已删除", "{:__URL('PLATFORM_MAIN/Goods/GoodsVariety')}");
                            } else {
                                showMessage('error', "删除异常");
                            }
                        }
                    })
                },
                "取消": function () {
                    $(this).dialog('close');
                }
            },
            contentText: "你确定删除",
            title: "消息提醒"
        });
    }

    function lock(uid) {
        $.ajax({
            type: "post",
            url: "{:__URL('PLATFORM_MAIN/auth/userlock')}",
            async: true,
            data: {
                "uid": uid,
            },
            success: function (data) {
                if (data["code"] > 0) {
                    showMessage('success', data["message"], "{:__URL('PLATFORM_MAIN/auth/userlist')}");
                } else {
                    showMessage('error', data["message"]);
                }
            }
        });
    }

    function unlock(uid) {
        $.ajax({
            type: "post",
            url: "{:__URL('PLATFORM_MAIN/auth/userunlock')}",
            async: true,
            data: {
                "uid": uid,
            },
            success: function (data) {
                if (data["code"] > 0) {
                    showMessage('success', data["message"], "{:__URL('PLATFORM_MAIN/auth/userlist')}");
                } else {
                    showMessage('error', data["message"]);
                }
            }
        });
    }

    function sort(uid, obj) {
        var sort = type = 0;
        if (obj == 1 || obj == 2) {
            type = obj;
        } else {
            sort = $(obj).val();
        }
        $.ajax({
            type: "post",
            url: "{:__URL('PLATFORM_MAIN/Goods/Newtype')}",
            async: true,
            data: {
                "variety_id": uid,
                "sort": sort,
                "type": type,
            },
            success: function (data) {
                LoadingInfo(1);
            }
        });
    }


    $("#search_text").keypress(function (e) {
        if (e.keyCode == 13) {
            LoadingInfo(1);
        }
    });
</script>
{/block}
